package com.example.theorygame.layer;

import android.view.MotionEvent;

import com.example.theorygame.util.CommouUtils;

import org.cocos2d.nodes.CCSprite;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.CGRect;

public class SixthLayer extends BaseLayer {
    private CCSprite bg6, bg3, bg2;
    private CCSprite button, button2;
    private boolean buttonrook = true;
    private boolean buttonrook2 = false;
    private CCSprite playagain;
    private boolean again = false;

    public SixthLayer() {
        bg6 = CCSprite.sprite("image/layer6/bg7.png");
        bg6.setAnchorPoint(0, 0);
        bg6.setPosition(0, 0);
        this.addChild(bg6);

        button = CCSprite.sprite("image/layer6/bbbb.png");
        button.setAnchorPoint(0, 0);
        button.setPosition(290, 27);
        this.addChild(button);

        buttonrook = true;
        setIsTouchEnabled(true);
    }

    /**
     * 触摸事件
     */
    @Override
    public boolean ccTouchesBegan(MotionEvent event) {
        CGPoint conver = this.convertTouchToNodeSpace(event);
        if (again) {
            if (CGRect.containsPoint(playagain.getBoundingBox(), conver)) {
                CommouUtils.changeLayer(new FirstLayer());
            }

        }
        if (buttonrook2) {
            if (CGRect.containsPoint(button2.getBoundingBox(), conver)) {
                bg3.removeSelf();
                button2.removeSelf();

                bg2 = CCSprite.sprite("image/layer6/last.png");
                bg2.setAnchorPoint(0, 0);
                bg2.setPosition(0, 0);
                this.addChild(bg2);

                playagain = CCSprite.sprite("image/layer6/again.png");
                playagain.setAnchorPoint(0, 0);
                playagain.setPosition(200, 0);
                this.addChild(playagain);

                again = true;
            }
        }
        if (buttonrook) {
            if (CGRect.containsPoint(button.getBoundingBox(), conver)) {
                bg6.removeSelf();
                button.removeSelf();

                bg3 = CCSprite.sprite("image/layer6/bggg.png");
                bg3.setAnchorPoint(0, 0);
                bg3.setPosition(0, 0);
                this.addChild(bg3);

                button2 = CCSprite.sprite("image/layer6/fx.png");
                button2.setAnchorPoint(0, 0);
                button2.setPosition(156, 5);
                this.addChild(button2);

                buttonrook2 = true;
            }
        }


        return true;

    }
}
